package jp.sourceforge.akjrcp.flvtools.explorer;

import java.io.File;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.InputEvent;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.Panel;
import org.eclipse.swt.graphics.Image;

public class ImageAndLabelFigure extends Panel{
	Label titleLabel;

	Label imageLabel;

	boolean hasExtension = true;

	
	boolean selection;
	
	LineBorder lineBorder; 
	MarginBorder marginBorder;
	
	private String realName;
	
	private String extension="flv";
	
	private String fileName; //for some action
	public String trimTitle(String name) {
		return name.substring(0, Math.min(16, name.length()));
	}
	
	public void setSelection(boolean bool){
		if(this.selection!=bool){
		this.selection=bool;
		if(selection){
			
			this.setBorder(lineBorder);
		}else{
			this.setBorder(marginBorder);
		}
		repaint();
		}
	}
	public boolean isSelection(){
		return selection;
	}
	public void turnSelection(){
		setSelection(!selection);
	}
	public void setImage(Image img) {
		if (img != null) {
			imageLabel.setIcon(img);
		} else {
			
		}
	}

	public String getLabel() {
		return titleLabel.getText();
	}

	public void setLabel(String text) {
		titleLabel.setText(text);
	}


	
	public ImageAndLabelFigure(String label, Image img) {
	super();
	realName=label;//bug fix for 
	this.setLayoutManager(new FlowLayout(false));
	imageLabel = new Label(img);
	
	add(imageLabel);
	titleLabel = new Label(trimTitle(label));
	add(titleLabel);
	
	
	
	lineBorder = new LineBorder();
	lineBorder.setColor(ColorConstants.green);
	lineBorder.setWidth(2);
	
	marginBorder=new MarginBorder(2);
	this.setBorder(marginBorder);
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
}
